﻿@model WebCore.Models.ViewModels.File.Admin._FileManagerViewModel
<div class="up">
    @if (Model.Root.Parent != null)
    {            
        <div>
            <a href="Javascript:LoadFolder('@Model.Root.Parent.Name',  '@Model.Root.Parent.Path')" id="parentFolder">
                @Model.Root.Parent.Name</a><span id="currentFolder">@(new MvcHtmlString( Model.Root.Name == Model.Root.Path?"":("/" + Model.Root.Name)))</span></div>
    }
</div>
<div class="cover">
    @foreach (WebCore.Models.DataManagers.Folder f2 in Model.Root.SubFolders)
    {             
        <div style="width: 100%">
            <a href="Javascript:LoadFolder('@f2.Name',  '@f2.Path')" class="folder">@f2.Name</a>
            <a href="Javascript:DeleteFolder('@f2.Name', '@f2.Path')" class="delete" style="float:right">
                &nbsp;</a>
        </div>
    }
    @foreach (WebCore.Models.DataManagers.File f in Model.Root.Files)
    {             
        <div style="width: 100%" id="@f.Name.Replace(".", "_").Replace(" ", "_")">
            <a  href="Javascript:LoadMedia('/@Model.Root.Path/@f.Name', '@f.Name', '@f.Name.Replace(".", "_").Replace(" ", "_")')" class="file">@f.Name</a>
            <a href="Javascript:DeleteFile('@f.Name', '@Model.Root.Path')" class="delete" style="float:right">
                &nbsp;</a></div>
    }
</div>
<script type="text/javascript">
    var currentRootPath = '@Model.Root.Path';
    var currentRootName = '@Model.Root.Name';
    var currentParentPath = '@(new MvcHtmlString(Model.Root.Parent != null?Model.Root.Parent.Path:""))';
    var currentParentName = '@(new MvcHtmlString(Model.Root.Parent != null?Model.Root.Parent.Name:""))';

    $('.progressbar').progressbar({ value: 0 });
    $('#newFolderName').val('');

    $('#file_upload').fileupload({
        dataType: 'json',
        url: '/File/UploadFile?rootPath=' + currentRootPath,
        progressall: function (e, data) {
            $('.progressbar').progressbar({ value: parseInt(data.loaded / data.total * 100, 10) });
        },
        done: function (e, data) {
            var error = data.result.errorMessage;
            if (error == "Success") {
                alert('Thêm file mới thành công');
                RefreshFileList();
            }
            else
                alert(error);
        }
    });

</script>
